package com.tgpms.web.pipenet.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PutMapping;
import javax.servlet.http.HttpServletRequest;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import com.tgpms.auth.security.TokenService;
import java.io.Serializable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.web.pipenet.entity.AppInParts;
import com.tgpms.web.pipenet.service.IAppInPartsService;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 管网app 部件表 控制层
 * </p>
 *
 * @author newway
 * @since 2020-10-30
 */
@Api(value = "AppInPartsController", tags = "管网app 部件表相关接口")
@RestController
@RequestMapping("/ev/AppInParts")
public class AppInPartsController {

	private final Logger log = LoggerFactory.getLogger(AppInPartsController.class);

	@Autowired
	private IAppInPartsService iIAppInPartsService;
	@Resource
	private TokenService tokenService;

	@ApiOperation(value = "新增管网app 部件表接口",notes = "新增管网app 部件表接口",httpMethod = "POST")
	@PostMapping(value = "/addAppInPartsInfo")
	public Result<String> addAppInPartsInfo(@RequestBody AppInParts en,HttpServletRequest request) {
		log.info("新增管网app 部件表接口接收到的参数为: "+en.toString());
		try{
			String insertName = tokenService.getUserName(request);
			en.setInsertUser(insertName);
			Result<String> result = iIAppInPartsService.addAppInParts(en);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return Result.ERROR(ExceptionExplain.ERROR_BY_INSERT.getExplain());
		}
	}

	@ApiOperation(value = "修改管网app 部件表接口",notes = "修改管网app 部件表接口",httpMethod = "PUT")
	@PutMapping(value = "/updateAppInPartsInfo")
	public Result<String> updateAppInPartsInfo(@RequestBody AppInParts en,HttpServletRequest request) {
		log.info("修改管网app 部件表接口接收到的参数为: "+en.toString());
		try{
			String insertName = tokenService.getUserName(request);
			en.setModifyUser(insertName);
			Result<String> result = iIAppInPartsService.updateAppInParts(en);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return Result.ERROR(ExceptionExplain.ERROR_BY_UPDATE.getExplain());
		}
	}

	@ApiOperation(value = "删除管网app 部件表接口",notes = "删除管网app 部件表接口",httpMethod = "DELETE")
	@DeleteMapping(value = "/deleteAppInPartsInfo")
	public Result<String> deleteAppInPartsInfo(@RequestParam Serializable id,HttpServletRequest request) {
		log.info("删除管网app 部件表接口接收到的参数为: {id: "+id+" }");
		try{
			Result<String> result = iIAppInPartsService.deleteAppInParts(id);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return Result.ERROR(ExceptionExplain.ERROR_BY_DELETE.getExplain());
		}
	}
}
